package com.springboot.rookie.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

//templates目录下的所有页面，只能通过controller来跳转!
//这个需要模板引擎的支持!
@Configuration
public class MyMvcConfig implements WebMvcConfigurer {

    //视图跳转
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("index");
        registry.addViewController("/index").setViewName("index");
        registry.addViewController("/register").setViewName("auth-register");
        registry.addViewController("/reset-password").setViewName("auth-reset-password");
        registry.addViewController("/main").setViewName("home");
        registry.addViewController("/pages-error-404").setViewName("error/404");
        registry.addViewController("/auto-login").setViewName("auto-login");
    }

    //自定义国际化组建
    @Bean
    public LocaleResolver localeResolver() {
        return new MyLocaleResolver();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginHandlerInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/index","/","/login","/css/**","/js/**","/img/**","/assets/**");
    }
}
